package com.day3sockettest.QQChat;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

public class ClientThread extends Thread{
    private Socket socket;
    private ClientChatMain clientChatMain;
    public ClientThread(Socket socket, ClientChatMain clientChatMain){
        this.socket = socket;
        this.clientChatMain = clientChatMain;
    }
    BufferedReader br = null;
    @Override
    public void run() {
        String str = null;
        try {
            br = new BufferedReader(new InputStreamReader( socket.getInputStream()));
            while (!(str=br.readLine()).equals("exit")){
                System.out.println(str);
                clientChatMain.getJta().append(str + System.lineSeparator());
            }
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
